package com.xiaoxi.commandmode.drawer;

import com.xiaoxi.commandmode.command.MacroCommand;

import java.awt.*;

/**
 * @Author xiaoxi
 * @ProjectName design_mode
 * @PackageName com.xiaoxi.commandmode.drawer
 * @ClassName DrawCanvas
 * @Description TODO
 * @Date 2023/4/15 11:12
 * @Version 1.0
 */
public class DrawCanvas extends Canvas implements Drawable {

    private Color color = Color.RED;

    private int radius = 6;

    // 历史记录
    private MacroCommand history;

    public DrawCanvas(MacroCommand macroCommand, int width, int height) {
        this.history = macroCommand;
        setSize(width, height);
        setBackground(Color.WHITE);
    }

    // 历史记录也叫
    public void paint(Graphics g) {
        history.execute();
    }

    @Override
    public void draw(int x, int y) {
        Graphics g = getGraphics();
        g.setColor(color);
        g.fillOval(x - radius, y - radius, radius * 2, radius * 2);
    }
}
